


** WORKING MEMORY **

	// Digit Recall

		foreach p in b e {

		// Span Index

			gen fordigscore_`p' = .
				la var fordigscore_`p' "Forward Digit Score"

			* Version 1 (p1_b and p1_e3wks)
			replace fordigscore_`p' = 8 if digtest8_1v1_`p' == 1 & fordigscore_`p'==.
			replace fordigscore_`p' = 7 if digtest7_1v1_`p' == 1 & fordigscore_`p'==.
			replace fordigscore_`p' = 6 if digtest6_2v1_`p' == 1 & fordigscore_`p'==.
			replace fordigscore_`p' = 5.5 if digtest6_1v1_`p' == 1 & fordigscore_`p'==.
			replace fordigscore_`p' = 5 if digtest5_2v1_`p' == 1 & fordigscore_`p'==.
			replace fordigscore_`p' = 4.5 if digtest5_1v1_`p' == 1 & fordigscore_`p'==.
			replace fordigscore_`p' = 4 if digtest4_2v1_`p' == 1 & fordigscore_`p'==.
			replace fordigscore_`p' = 3.5 if digtest4_1v1_`p' == 1 & fordigscore_`p'==.
			replace fordigscore_`p' = 3 if digtest3_2v1_`p' == 1 & fordigscore_`p'==.
			replace fordigscore_`p' = 2.5 if digtest3_1v1_`p' == 1 & fordigscore_`p'==.
			replace fordigscore_`p' = 2 if digtest2_1v1_`p' == 1 & fordigscore_`p'==.
			replace fordigscore_`p' = 0 if digtest2_1v1_`p' == 0 & fordigscore_`p'==.

			* Version 2
			replace fordigscore_`p' = 9 if digtest9_2v2_`p' == 1 & fordigscore_`p'==.
			replace fordigscore_`p' = 9 if digtest9_1v2_`p' == 1 & fordigscore_`p'==.
			replace fordigscore_`p' = 8 if digtest8_2v2_`p' == 1 & fordigscore_`p'==.
			replace fordigscore_`p' = 8 if digtest8_1v2_`p' == 1 & fordigscore_`p'==.
			replace fordigscore_`p' = 7 if digtest7_2v2_`p' == 1 & fordigscore_`p'==.
			replace fordigscore_`p' = 7 if digtest7_1v2_`p' == 1 & fordigscore_`p'==.
			replace fordigscore_`p' = 6 if digtest6_2v2_`p' == 1 & fordigscore_`p'==.
			replace fordigscore_`p' = 6 if digtest6_1v2_`p' == 1 & fordigscore_`p'==.
			replace fordigscore_`p' = 5 if digtest5_2v2_`p' == 1 & fordigscore_`p'==.
			replace fordigscore_`p' = 5 if digtest5_1v2_`p' == 1 & fordigscore_`p'==.
			replace fordigscore_`p' = 4 if digtest4_2v2_`p' == 1 & fordigscore_`p'==.
			replace fordigscore_`p' = 4 if digtest4_1v2_`p' == 1 & fordigscore_`p'==.
			replace fordigscore_`p' = 3 if digtest3_2v2_`p' == 1 & fordigscore_`p'==.
			replace fordigscore_`p' = 3 if digtest3_1v2_`p' == 1 & fordigscore_`p'==.
			replace fordigscore_`p' = 2 if digtest2_2v2_`p' == 1 & fordigscore_`p'==.
			replace fordigscore_`p' = 2 if digtest2_1v2_`p' == 1 & fordigscore_`p'==.
			replace fordigscore_`p' = 0 if digtest2_1v2_`p' == 0 & digtest2_1v2_`p' == 0 & fordigscore_`p'==.


		// Working memory index

			gen backdigscore_`p' = .
				la var backdigscore_`p' "Backward Digit Score"

			* Version1
			replace backdigscore_`p' = 6 if digopptest6_2v1_`p'==1 & backdigscore_`p'==.
			replace backdigscore_`p' = 5.5 if digopptest6_1v1_`p'==1 & backdigscore_`p'==.
			replace backdigscore_`p' = 5 if digopptest5_2v1_`p'==1 & backdigscore_`p'==.
			replace backdigscore_`p' = 4.5 if digopptest5_1v1_`p'==1 & backdigscore_`p'==.
			replace backdigscore_`p' = 4 if digopptest4_2v1_`p'==1 & backdigscore_`p'==.
			replace backdigscore_`p' = 3.5 if digopptest4_1v1_`p'==1 & backdigscore_`p'==.
			replace backdigscore_`p' = 3 if digopptest3_2v1_`p'==1 & backdigscore_`p'==.
			replace backdigscore_`p' = 2.5 if digopptest3_1v1_`p'==1 & backdigscore_`p'==.
			replace backdigscore_`p' = 2 if digopptest2_1v1_`p'==1 & backdigscore_`p'==.
			replace backdigscore_`p' = 0 if digopptest2_1v1_`p'==0 & digopptest3_1v1_`p'==0

			* Version 2
			replace backdigscore_`p' = 8 if digopptest8_2v2_`p' == 1 & backdigscore_`p'==.
			replace backdigscore_`p' = 8 if digopptest8_1v2_`p' == 1 & backdigscore_`p'==.
			replace backdigscore_`p' = 7 if digopptest7_2v2_`p' == 1 & backdigscore_`p'==.
			replace backdigscore_`p' = 7 if digopptest7_1v2_`p' == 1 & backdigscore_`p'==.
			replace backdigscore_`p' = 6 if digopptest6_2v2_`p' == 1 & backdigscore_`p'==.
			replace backdigscore_`p' = 6 if digopptest6_1v2_`p' == 1 & backdigscore_`p'==.
			replace backdigscore_`p' = 5 if digopptest5_2v2_`p' == 1 & backdigscore_`p'==.
			replace backdigscore_`p' = 5 if digopptest5_1v2_`p' == 1 & backdigscore_`p'==.
			replace backdigscore_`p' = 4 if digopptest4_2v2_`p' == 1 & backdigscore_`p'==.
			replace backdigscore_`p' = 4 if digopptest4_1v2_`p' == 1 & backdigscore_`p'==.
			replace backdigscore_`p' = 3 if digopptest3_2v2_`p' == 1 & backdigscore_`p'==.
			replace backdigscore_`p' = 3 if digopptest3_1v2_`p' == 1 & backdigscore_`p'==.
			replace backdigscore_`p' = 2 if digopptest2_2v2_`p' == 1 & backdigscore_`p'==.
			replace backdigscore_`p' = 2 if digopptest2_1v2_`p' == 1 & backdigscore_`p'==.
			replace backdigscore_`p' = 0 if digopptest2_1v2_`p' == 0 & digopptest2_2v2_`p' == 0 & backdigscore_`p'==.

		// Working Memory and Attention Span Index

			gen workingmemscore_`p' = fordigscore_`p' - backdigscore_`p'
				la var workingmemscore_`p' "Working Mem Score"

			egen workingmemindex_`p' =std(workingmemscore_`p')
				la var workingmemindex_`p' "Working Men Index Mean 0, Sd 1"

			gen attentionspanindex_`p' = fordigscore_`p'
				la var attentionspanindex_`p' "Span Index"

		}

		* Frog

			egen frogillmove_b = rowtotal(g5g1g_b g5g2g_b g5g3g_b g5g4g_b g5g5g_b)
			replace frogillmove_b = . if g5g1g_b ==. & g5g2g_b==. & g5g3g_b==. & g5g4g_b==. & g5g5g_b==.
				la var frogillmove_b "Frog: Nb of illegal move"

			gen frogillmoveavg_b = frogillmove_b/5
				la var frogillmoveavg_b "Frog: Nb of illegal move (total / 5)"


			// Time per-move ratio: Total completion times across all items administered/total number of moves across all items administered.
				// We calculate for each games and then average

				forval i = 1/5 {
					gen frog`i'timepermove_b =	g5g`i'esec_b / g5g`i'f_b+ g5g`i'g_b
						la var frog`i'timepermove_b "Frog: Time per Move F`i'"
				}

				gen frogtimepermove_b = (frog1timepermove_b + frog2timepermove_b +  frog3timepermove_b + frog4timepermove_b + frog5timepermove_b)/5
					la var frogtimepermove_b "Frog: Time per Move (sec) average across frog games"


				foreach var in  frog1timepermove frog2timepermove frog3timepermove frog4timepermove frog5timepermove frogtimepermove {
					egen `var'std_b =std(`var'_b)
				}


			// Move Accuracy ratio: Total number of moves across all items administered/total number of minimum moves required across all items administered

				gen frog1moveaccratio_b = (g5g1f_b + g5g1g_b)/2
					la var frog1moveaccratio_b "Frog: Move accuracy Ratio F1"

				gen frog2moveaccratio_b = (g5g2f_b + g5g2g_b)/3
					la var frog2moveaccratio_b "Frog: Move accuracy Ratio F2"

				gen frog3moveaccratio_b = (g5g3f_b + g5g3g_b)/4
					la var frog3moveaccratio_b "Frog: Move accuracy Ratio F3"

				gen frog4moveaccratio_b = (g5g4f_b + g5g4g_b)/5
					la var frog4moveaccratio_b "Frog: Move accuracy Ratio F4"

				gen frog5moveaccratio_b = (g5g5f_b + g5g5g_b)/7
					la var frog5moveaccratio_b "Frog: Move accuracy Ratio f5"

				gen frogmoveaccratio_b = (frog1moveaccratio_b + frog2moveaccratio_b + frog3moveaccratio_b +frog4moveaccratio_b+ frog5moveaccratio_b)/5
					la var frogmoveaccratio_b "Frog: Move accuracy Ratio"

				foreach var in  frogmoveaccratio frog1moveaccratio frog2moveaccratio frog3moveaccratio frog4moveaccratio frog5moveaccratio {
					egen `var'std_b =std(`var'_b)
				}

			// DKEFS Score

				// Frog 1
					gen frog1score_b =  2 if g5g1f_b==2
					replace frog1score_b =  1 if g5g1f_b>2 & g5g1f_b!=. & g5g1d_b ==1
					replace frog1score_b = 0 if g5g1d_b==0
						la var frog1score_b "Frog: score F1"

				// Frog 2
					gen frog2score_b = 3 if g5g2f_b ==3
					replace frog2score_b = 2 if g5g2f_b ==4
					replace frog2score_b = 1 if g5g2f_b > 4 & g5g2f_b !=. & g5g2d_b==1
					replace frog2score_b = 0 if g5g2d_b==0
						la var frog2score_b "Frog: score F2"

				// Frog 3 . One survey nb of move is 3 when the mininmum is 4. For now we count it as 4
					gen frog3score_b = 3 if g5g3f_b == 4 | g5g3f_b==3
					replace frog3score_b = 2 if g5g3f_b == 5
					replace frog3score_b = 1 if g5g3f_b >5 & g5g3f_b!=. & g5g3d_b==1
					replace frog3score_b = 0 if g5g3d_b==0
						la var frog3score_b "Frog: score F3"

				// Frog 4. 2 people said 4 when the mininmun is 5. For now we count them as 5
					gen frog4score_b = 4 if g5g4f_b == 5 | g5g4f_b ==4
					replace frog4score_b = 3 if g5g4f_b == 6
					replace frog4score_b = 2 if g5g4f_b == 7
					replace frog4score_b = 1 if g5g4f_b > 7 & g5g4f_b!=. & g5g4d_b==1
					replace frog4score_b = 0 if g5g4d_b==0
						la var frog4score_b "Frog: score F4"

				// Frog 5 6 people said 5 or 6 when the minimum is 7
					gen frog5score_b = 4 if g5g5f_b == 7
					replace frog5score_b = 3 if g5g5f_b ==8
					replace frog5score_b = 2 if g5g5f_b ==9
					replace frog5score_b = 1 if g5g5f_b >9 & g5g5f_b!=. & g5g5d_b==1
					replace frog5score_b = 0 if g5g5d_b==0
						la var frog5score_b "Frog: score F5"

				// Total and avg score
					egen frogscoretot_b = rowtotal (frog1score_b frog2score_b  frog3score_b frog4score_b frog5score_b)
						la var frogscoretot_b "Frog: Total Score"

					gen frogscoreavg_b = frogscoretot_b/5
						la var frogscoreavg_b "Frog: Avg Score"
